import java.util.ArrayList;


public class Board {
	private Block[] block = new Block[40];
	@SuppressWarnings("unchecked")
	ArrayList<Estate>[] colorGroupList = new ArrayList[8];
	private int[] colorGroupSize = new int[8];
	//number types:
	//1 = estate
	//2 = airport
	//3 = utility
	//4 = chest
	//5 = chance
	//6 = tax
	
	public Board() {
		block[0] = new Block("Go",0);
		block[1] = new Block(new Estate("Cleaveland","Jacob's Field",1, 600000, 0, new TitleDeed(20000, 100000, 300000, 9000000, 1600000, 2500000, 300000, 500000)));
		block[2] = new Block(new Chest("Community Chest",2));								//chest
		block[3] = new Block(new Estate("Dallas","Texas Stadium",3,600000, 0, new TitleDeed(40000, 200000, 600000, 1800000, 3200000, 4500000, 300000, 500000)));
		block[4] = new Block(new Tax("Income tax",4));			//tax
		block[5] = new Block(new Airport("Airport","O'hare Airport",5,2000000, new TitleDeed(250000, 500000, 1000000, 2000000, 1000000)));		//airport
		block[6] = new Block(new Estate("Nashville","Grand Ole Opry",6,1000000, 1, new TitleDeed(60000, 300000, 900000, 2700000, 4000000, 5500000, 500000, 500000)));
		block[7] = new Block(new Chance("Chance",7));			//chance
		block[8] = new Block(new Estate("St. Louis","Gateway Arch",8,1000000, 1, new TitleDeed(60000, 300000, 900000, 2700000, 4000000, 5500000, 500000, 500000)));
		block[9] = new Block(new Estate("Minneapolis","Mall Of America",9, 1200000, 1, new TitleDeed(80000, 400000, 1000000, 3000000, 4500000, 6000000, 600000, 500000)));
		block[10] = new Block("Jail",10);
		
		block[11] = new Block(new Estate("Atlanta","Centennial Olympic Park",11,1400000, 2, new TitleDeed(100000, 500000, 1500000, 4500000, 6250000, 7500000, 700000, 1000000)));
		block[12] = new Block(new Utility("Service Provider","Phone Service Provider",12,1500000, new TitleDeed(40000, 100000, 750000)));
		block[13] = new Block(new Estate("Denver","Red Rocks Amphitheatre",13,1400000, 2, new TitleDeed(100000, 500000, 1500000, 4500000, 6250000, 7500000, 700000, 1000000)));
		block[14] = new Block(new Estate("Philadelphia","Liberty Bell",14,1600000, 2, new TitleDeed(120000, 600000, 1800000, 5000000, 7000000, 9000000, 800000, 1000000)));
		block[15] = new Block(new Airport("Airport","Los Angeles Airport",15,2000000, new TitleDeed(250000, 500000, 1000000, 2000000, 1000000)));		//airport
		block[16] = new Block(new Estate("Miami","South Beach",16,1800000, 3, new TitleDeed(140000, 700000, 2000000, 5500000, 7500000, 9500000, 900000, 1000000)));
		block[17] = new Block(new Chest("Community Chest",17));	//chest
		block[18] = new Block(new Estate("Houston","Johnson Space Center",18,1800000, 3, new TitleDeed(140000, 700000, 2000000, 5500000, 7500000, 9500000, 900000, 1000000)));
		block[19] = new Block(new Estate("Seattle","Pioneer Square",19,2000000, 3, new TitleDeed(160000, 800000, 2200000, 6000000, 8000000, 10000000, 1000000, 1000000)));
		block[20] = new Block("Parking",20);
		
		block[21] = new Block(new Estate("Phoenix","Camelback Mtn.",21,2200000, 4, new TitleDeed(180000, 900000, 2500000, 7000000, 8750000, 10500000, 1100000, 1500000)));
		block[22] = new Block(new Chance("Chance",22));			//chance
		block[23] = new Block(new Estate("Honolulu","Waikiki Beach",23,2200000, 4, new TitleDeed(180000, 900000, 2500000, 7000000, 8750000, 10500000, 1100000, 1500000)));
		block[24] = new Block(new Estate("Orlando","Disney World",24,2400000, 4, new TitleDeed(200000, 1000000, 3000000, 7500000, 9250000, 11000000, 1200000, 1500000)));
		block[25] = new Block(new Airport("Airport","John F. Kennedy Airport",25,2000000, new TitleDeed(250000, 500000, 1000000, 2000000, 1000000)));
		block[26] = new Block(new Estate("New Orleans","French Quarter",26,2600000, 5, new TitleDeed(220000, 1100000, 3300000, 8000000, 9750000, 11500000, 1300000, 1500000)));
		block[27] = new Block(new Estate("Los Angeles","Hollywood",27,2600000, 5, new TitleDeed(220000, 1100000, 3300000, 8000000, 9750000, 11500000, 1300000, 1500000)));
		block[28] = new Block(new Utility("Service Provider","Internet Service Provider",28,1500000, new TitleDeed(40000, 100000, 750000)));
		block[29] = new Block(new Estate("San Francisco","Golden Gate Bridge",29,2800000, 5, new TitleDeed(240000, 1200000, 3600000, 8500000, 10250000, 12000000, 1400000, 1500000)));
		block[30] = new Block("Go to Jail",30);
		
		block[31] = new Block(new Estate("Las Vegas","Las Vegas Blvd.",31,3000000, 6, new TitleDeed(260000, 1300000, 3900000, 9000000, 11000000, 12750000, 1500000, 2000000)));
		block[32] = new Block(new Estate("Chicago","Wringley Field",32,3000000,6, new TitleDeed(260000, 1300000, 3900000, 9000000, 11000000, 12750000, 1500000, 2000000)));
		block[33] = new Block(new Chest("Community Chest",33));	//chest
		block[34] = new Block(new Estate("Washington, D.C.","White House",34,3200000, 6, new TitleDeed(280000, 1500000, 4500000,10000000, 12000000, 14000000, 1600000, 2000000)));
		block[35] = new Block(new Airport("Airport","Hartsfield-Jackson Airport",35,2000000, new TitleDeed(250000, 500000, 1000000, 2000000, 1000000)));
		block[36] = new Block(new Chance("Chance",36));			//chance
		block[37] = new Block(new Estate("Boston","Fenway Park",37,3500000, 7, new TitleDeed(350000, 1750000, 5000000, 11000000, 13000000, 15000000, 1750000, 2000000)));
		block[38] = new Block(new Tax("Credit Card Debt",4));	//tax
		block[39] = new Block(new Estate("New York","Times Square",39,4000000, 7, new TitleDeed(500000, 2000000, 6000000, 14000000, 17000000, 20000000, 2000000, 2000000)));
		
        colorGroupSize[0] = 2;
        colorGroupSize[1] = 3;
        colorGroupSize[2] = 3;
        colorGroupSize[3] = 3;
        colorGroupSize[4] = 3;
        colorGroupSize[5] = 3;
        colorGroupSize[6] = 3;
        colorGroupSize[7] = 2;
        
        for(int i=0;i<8;i++){
        	colorGroupList[i] = new ArrayList<Estate>();
        }
        
        colorGroupList[0].add(block[1].getEstate());
        colorGroupList[0].add(block[3].getEstate());
        
        colorGroupList[1].add(block[6].getEstate());
        colorGroupList[1].add(block[8].getEstate());
        colorGroupList[1].add(block[9].getEstate());
        
        colorGroupList[2].add(block[11].getEstate());
        colorGroupList[2].add(block[13].getEstate());
        colorGroupList[2].add(block[14].getEstate());
        
        colorGroupList[3].add(block[16].getEstate());
        colorGroupList[3].add(block[18].getEstate());
        colorGroupList[3].add(block[19].getEstate());
        
        colorGroupList[4].add(block[21].getEstate());
        colorGroupList[4].add(block[23].getEstate());
        colorGroupList[4].add(block[24].getEstate());
        
        colorGroupList[5].add(block[26].getEstate());
        colorGroupList[5].add(block[27].getEstate());
        colorGroupList[5].add(block[29].getEstate());
        
        colorGroupList[6].add(block[31].getEstate());
        colorGroupList[6].add(block[32].getEstate());
        colorGroupList[6].add(block[34].getEstate());
        
        colorGroupList[7].add(block[37].getEstate());
        colorGroupList[7].add(block[39].getEstate());
	}


	public void setBlock(Block[] block) {
		this.block = block;
	}

	public Block[] getBlock() {
		return block;
	}
	public ArrayList<Estate>[] getColorGroupList() {
		return colorGroupList;
	}
	public void setColorGroupList(ArrayList<Estate>[] colorGroupList) {
		this.colorGroupList = colorGroupList;
	}

	public void setColorGroupSize(int[] colorGroupSize) {
		this.colorGroupSize = colorGroupSize;
	}


	public int[] getColorGroupSize() {
		return colorGroupSize;
	}
	
	public void checkNeighborProperties(Block[] block, int tileClicked){
		//A function that checks other properties within a colour group of a property that is chosen.
		//Its purpose is to determine if a player can build or sell houses equally.
		boolean[] tempHave = new boolean[3];
		boolean[] tempLose = new boolean[3];
		tempHave[0] = false;
		tempHave[1] = false;
		tempHave[2] = true;
		tempLose[0] = false;
		tempLose[1] = false;
		tempLose[2] = true;
		int colorGroup = block[tileClicked].getEstate().getColorGroup();
		
		for(int loopCtr = 0; getColorGroupList()[colorGroup].size() > loopCtr; loopCtr++){
			//for having house
			if(block[tileClicked].getEstate().getNumberOfHouse()<=getColorGroupList()[colorGroup].get(loopCtr).getNumberOfHouse()){
				tempHave[loopCtr] = true;
			}
			else{
				tempHave[loopCtr] = false;
			}
			//for losing house
			if(block[tileClicked].getEstate().getNumberOfHouse()>=getColorGroupList()[colorGroup].get(loopCtr).getNumberOfHouse()){
				tempLose[loopCtr] = true;
			}
			else{
				tempLose[loopCtr] = false;
			}
		}
		//makes the final judgement for having house
		if(tempHave[0]&&tempHave[1]&&tempHave[2]){
			block[tileClicked].getEstate().setCanHaveHouse(true);
		}
		else{
			block[tileClicked].getEstate().setCanHaveHouse(false);
		}
		//makes the final judgement for losing house
		if(tempLose[0]&&tempLose[1]&&tempLose[2]){
			block[tileClicked].getEstate().setCanLoseHouse(true);
		}
		else{
			block[tileClicked].getEstate().setCanLoseHouse(false);
		}
	}
	
}
